package com.wang.service.impl;

import com.wang.bean.Emp;
import com.wang.mapper.EmpMapper;
import com.wang.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

@Service
@Transactional
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpMapper empMapper;

    @Override
    //设置查询的时候不开启事务
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Emp> getAll() {
        return empMapper.getAll();
    }

    @Override
    public void addEmp(Emp emp) {
        emp.setId(UUID.randomUUID().toString());
        empMapper.addEmp(emp);
    }

    @Override
    public void del(String id) {
        empMapper.del(id);
    }

    @Override
    public Emp getEmpById(String id) {
        return empMapper.getEmpById(id);
    }

    @Override
    public void update(Emp emp) {
        empMapper.update(emp);
    }
}
